package logic

import (
	"context"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	"user_srv/model"
	"user_srv/user_proto"
)

func (s *Server) GetBooksByName(ctx context.Context, in *user_proto.GetBooksByNameRequest) (*user_proto.GetBooksByNameResponse, error) {
	name, err := model.GetBooksByName(int(in.Id))
	if err != nil {
		return nil, status.Errorf(codes.Internal, "查询漫画失败")
	}
	return &user_proto.GetBooksByNameResponse{
		Id:      int64(name.ID),
		Name:    name.Name,
		Content: name.Content,
		Types:   name.Types,
		Author:  name.Author,
		Hot:     int64(name.Hot),
	}, nil
}
